package com.zzyl.serve.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzyl.serve.domain.Floor;
import com.zzyl.serve.vo.TreeVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 楼层Mapper接口
 * 
 * @author howstrong
 * @date 2025-03-03
 */
@Mapper
public interface FloorMapper extends BaseMapper<Floor>
{
    /**
     * 查询楼层
     * 
     * @param id 楼层主键
     * @return 楼层
     */
    public Floor selectFloorById(Long id);

    /**
     * 查询楼层列表
     * 
     * @param floor 楼层
     * @return 楼层集合
     */
    public List<Floor> selectFloorList(Floor floor);

    /**
     * 新增楼层
     * 
     * @param floor 楼层
     * @return 结果
     */
    public int insertFloor(Floor floor);

    /**
     * 修改楼层
     * 
     * @param floor 楼层
     * @return 结果
     */
    public int updateFloor(Floor floor);

    /**
     * 删除楼层
     * 
     * @param id 楼层主键
     * @return 结果
     */
    public int deleteFloorById(Long id);

    /**
     * 批量删除楼层
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteFloorByIds(Long[] ids);


    /*
     * 根据床位状态查询获取所有楼层、床位数据
     *@param status
     *@return*/
    List<TreeVo> getRoomAndBedByBedStatus(Integer status);
@Select("select *\n" +
        "from floor f\n" +
        "left join room r on f.id = r.floor_id\n" +
        "left join bed b on r.id = b.room_id\n" +
        "left join device d1 on d1.binding_location = r.id and d1.location_type = 1 and d1.physical_location_type =1\n" +
        "left join device d2 on d2.binding_location = b.id and d2.location_type = 1 and d2.physical_location_type =2\n" +
        "where d1.id is not null or d2.id is not null\n" +
        "group by f.id\n" +
        "order by f.id asc")
    List<Floor> getAllFloorsWithDevice();
}
